#ifndef VDCORECHAT_H
#define VDCORECHAT_H

#include <QObject>

#include "VDEnums.h"
#include "VDProtocol.h"

class QUdpSocket;
class QHostAddress;

class VDUser;
//class VDProtocol;
class VDUserList;

class VDCoreChat : public QObject
{
	Q_OBJECT

public:
	VDCoreChat(VDUser *master, int port, QObject *parent);
	~VDCoreChat();

	bool setEnabledChat(bool enable);
	bool isEnabledChat();

	const VDUser* getMaster() const {return m_master;}
	VDUser* getMaster() {return m_master;}
	VD::UserState getMasterState() const;

	void readSettingList();
	void writeSettingList();

protected:
	virtual void timerEvent(QTimerEvent *te);

private:
	void send(const QByteArray &ba);

private:
	QUdpSocket *m_udpSocket;
	bool m_isImInNetwork;

	int m_timerID;
	int m_port;
	VDUser *m_master;
	VDProtocol *m_protocol;
	VDUserList *m_userList;


public slots:
//	void send(QString str);
	void setMasterState(VD::UserState us);
	void sendMessage(const QString&, const VDUser&);
	void sendChatMessage(const QString&);


private slots:
	void slotRead();
	void slot_MES_USER_INFO_SHORT(const ShortInfo &sender);
	void slot_MES_USER_INFO_FULL(const VDUser &user);
	void slot_MES_TAKE_INFO_FULL(const ShortInfo &sender, 
		const QString &takeInfoID);

	void slot_MES_SEND_ONE(const ShortInfo &sender, 
		const QString &receiveID, const QString &text);

	void slot_MES_SEND_MANY(const ShortInfo &sender, 
		const QStringList &receiveIDs, const QString &text);

	void slot_MES_SEND_CHAT(const ShortInfo &sender, 
		const QString &text);

	void slot_MES_ANSWER(const ShortInfo &sender, 
		quint16 checkSumMes);

signals:
	void addUser(const VDUser &);
	//void removeUser(const VDUser &);
	void changeUser(const VDUser &);
	void changeStateUser(const VDUser&, VD::UserState);

	void changeMaster(const VDUser&);

	void recieveMesFromUser(const QString&, const VDUser&);
	void recieveChatFromUser(const QString&, const VDUser&);

};

#endif // VDCORECHAT_H
